import 'dart:async';

import 'package:course_control/config/com_header.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class TabbarController extends GetxController {
  final tabController = StreamController<int>();
  final pageController = PageController(initialPage: 0);

  final dateTimeStr = ''.obs;
  late Timer _timer;

  @override
  void onInit() {
    super.onInit();

    tabController.stream.listen((index) {
      pageController.jumpToPage(index);
    });

    initDate();
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      initDate();
    });
  }

  initDate() {
    var dateFormat = DateFormat('HH:mm MM月dd日 EEE', 'zh_CN');
    var date = DateTime.now();
    dateTimeStr.value = dateFormat.format(date);
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }
}
